<?php

namespace app\common\model;

use think\Model;
use think\Request;
use traits\model\SoftDelete;

class Staff extends Model
{
    use SoftDelete;
    // 表名
    protected $name = 'staff';
    protected $deleteTime = 'deletetime';
    // 追加属性
    protected $append = [
        'service_text',
        'service1_text',
    ];

    public function getAvatarAttr($value, $data)
    {
        $request = Request::instance();
        $domain=$request->domain();
        return $domain.$value;
    }

    public function getImageAttr($value, $data)
    {
        $request = Request::instance();
        $domain=$request->domain();
        return $domain.$value;
    }

    public function getImagesAttr($value, $data)
    {
        $request = Request::instance();
        $domain=$request->domain();
        $value = explode(',',$value);
        foreach ($value as &$item) {
            $item = $domain.$item;
        }
        return $value;
    }

//    public function getMobileAttr($value, $data)
//    {
//        $user = User::get($this->user_id);
//        //如果没购买
//        $value = substr_replace($value,'****',3,4);
//      return $value;
//    }
//
//    public function getAddressAttr($value, $data)
//    {
//        $user = User::get($this->user_id);
//        //如果没购买
//        $value = "************";
//        return $value;
//    }

    public function getServiceTextAttr($value, $data)
    {
        $model = new Service();
        $res = $model->where('id','in',$data['service_ids'])->select();
        $text = [];
        foreach ($res as $item) {
            $text[] = $item['name'];
        }
//        return implode(',', $text);
        return $text;
    }

    public function getService1TextAttr($value, $data)
    {
        $model = new Service();
        $res = $model->where('id','in',$data['service1_ids'])->select();
        $text = [];
        foreach ($res as $item) {
            $text[] = $item['name'];
        }
//        return implode(',', $text);
        return $text;
    }

    public function tag()
    {
        return $this->belongsTo('Tag', 'tag_id', 'id');
    }
}